<template>
    <el-table-column label="是否展示" min-width="100" align="center">
        <template #default="{ row }">
            <el-switch v-model="row.status" :active-value="1" :inactive-value="0" :loading="loading"
                @change="handleStatus(row)" />
        </template>
    </el-table-column>
</template>

<script setup lang="ts" name="SwitchShowStatus">
import { commonChangeStatus } from '@/api/common/CommonAPI';

import { ElMessage } from 'element-plus';
import { ref } from 'vue';

const props = defineProps({
    url: {
        type: String,
        required: true
    }
})

const emit = defineEmits(['update:modelValue']);

const loading = ref(false)

const handleStatus = async (row: any) => {
    try {
        loading.value = true
        const data = await commonChangeStatus(props.url, row.id as number, row.status as number)
        if (data.code === 200) {
            ElMessage.success('修改成功');
        } else {
            ElMessage.error('修改失败');
        }
    } finally {
        loading.value = false
    }
}
</script>

<style scoped lang="scss"></style>